﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Function : Father
    {
        public Function(string name, string playname) : base(name, playname)
        {
            
        }
        public Function() 
        {
        
        }
        public override void hello()
        {
            
            Console.WriteLine("{0}", this.name);
        }
        public void gamego() 
        {
            
            int playname1 = 0;
            int botname1 = 0;
            int pj = 0;
            
            Console.WriteLine("请选择对方角色<1:刘备 2:孙权 3:曹操>");
            string name = Console.ReadLine();
            if (name.Equals("1"))
            {
                Function function = new Function("刘备","");
                function.hello();
                name = "刘备";
                
            }
            else if (name.Equals("2"))
            {
                Function function1 = new Function("孙权","");
                function1.hello();
                name = "孙权";
            }
            else if (name.Equals("3"))
            {
                Function function2 = new Function("曹操","");
                function2.hello();
                name = "曹操";

            }
            Console.WriteLine("请输入您的姓名：");
            string playname = Console.ReadLine();
            Console.WriteLine("{0}vs{1} 对战",name, playname);

            Console.WriteLine("开始游戏吗？《y/n》");
            string game = Console.ReadLine();

            if (game.Equals("y"))
            {
                
                Console.WriteLine("请出拳：1.石头，2.剪刀，3.布（输入相应的数字）");
                int i = int.Parse(Console.ReadLine());
                if (i==1)
                {
                    Console.WriteLine("{0}:出拳：{1}",playname,Sjb.石头);
                    Random random = new Random();
                    int a = random.Next(1,4);
                    switch (a)
                    {
                        case 1:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.石头);
                            break;
                        case 2:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.剪刀);
                            break;
                        case 3:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.布);
                            break;
                        default:
                            break;
                    }
                    if (a==3)
                    {
                        Console.WriteLine("霉蛋{0}输了",playname);
                        botname1++;
                    }
                    else if(a==1)
                    {
                        Console.WriteLine("平局");
                        pj++;
                    }
                    else
                    {
                        Console.WriteLine("霉蛋{0}输了",name);
                        playname1++;
                    }
                  
                   
                   
                }
                else if (i==2)
                {
                    Console.WriteLine("{0}:出拳：{1}", playname, Sjb.剪刀);
                    Random random = new Random();
                    int a = random.Next(1, 4);
                    switch (a)
                    {
                        case 1:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.石头);
                            break;
                        case 2:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.剪刀);
                            break;
                        case 3:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.布);
                            break;
                        default:
                            break;
                    }
                    if (a==1)
                    {
                        Console.WriteLine("霉蛋{0}输了", playname);
                        botname1++;
                    }
                    else if (a == 2)
                    {
                        Console.WriteLine("平局");
                        pj++;
                    }
                    else
                    {
                        Console.WriteLine("霉蛋{0}输了", name);
                        playname1++;
                    }
                    pd2();
                   
                   
                    
                    
                }
                else if (i==3)
                {
                    Console.WriteLine("{0}:出拳：{1}", playname, Sjb.布);
                    Random random = new Random();
                    int a = random.Next(1, 4);
                    switch (a)
                    {
                        case 1:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.石头);
                            break;
                        case 2:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.剪刀);
                            break;
                        case 3:
                            Console.WriteLine("{0}:出拳：{1}", name, Sjb.布);
                            break;
                        default:
                            break;
                    }
                    if (a==2)
                    {
                        Console.WriteLine("霉蛋{0}输了", playname);
                        botname1++;
                    }
                    else if (a == 3)
                    {
                        Console.WriteLine("平局");
                        pj++;
                    }
                    else
                    {
                        Console.WriteLine("霉蛋{0}输了", name);
                        playname1++;
                    }

                }
                pd2();
                int sum = botname1 + playname1 + pj;
                function = sum;
                Console.WriteLine("-----------------------------------");
                Console.WriteLine("{0}vs{1}", this.name, this.playname);
                Console.WriteLine("对战次数：{0}", base.function);
                Console.WriteLine();
                Console.WriteLine("姓名     得分");
                Console.Write("{0}+\t",playname);
                Console.WriteLine("{0}       ",playname1);
                Console.Write("{0}+\t",name);
                Console.WriteLine("{0}       ", botname1);
                
                Console.WriteLine("结果");
                if (botname1 > playname1)
                {
                    Console.WriteLine("{0}胜利了",name);
                }
                else if (botname1 < playname1)
                {
                    Console.WriteLine("{0}胜利了", playname);
                }
                else
                {
                    Console.WriteLine("平局");
                }
                Console.WriteLine("要开始下一局吗？《y/n》");
                string game1 = Console.ReadLine();
                if (game1 == "y")
                {
                    gamego();
                }
                else if (game1 == "n")
                {
                    System.Environment.Exit(0);
                }
                else
                {
                    pd2();

                }
            }
            else if (game.Equals("n"))
            {
                System.Environment.Exit(0);
            }
            else
            {
                gamego();

            }

        }
        public void pd2() 
        {
            Console.WriteLine("是否开始下一轮《y/n》");
            string game = Console.ReadLine();
            if (game.Equals("y"))
            {
                gamego();
            }
            else if(game.Equals("n"))
            {
                
            }
            else
            {
                pd2();
            }
        }
        public void pd1() 
        {
        
        
        }
       
       
    }
}
